/*
 * Project Beknyou
 * Copyright (c) 2010-2011 Saint Paul College, All Rights Reserved
 * Redistributions in source code form must reproduce the above
 * Copyright and this condition.
 * The contents of this file are subject to the GNU General Public
 * License, Version 2 (the "License"); you may not use this file
 * except in compliance with the License. A copy of the License is
 * available at http://www.opensource.org/licenses/gpl-license.php.
 */
package com.benkyou.client.network;

import com.benkyou.client.GameClient;
import com.benkyou.common.messages.ChatClientMessage;
import com.jme3.network.Client;
import com.jme3.network.Message;
import com.jme3.network.MessageListener;

/**
 *
 * @author Austin Allman
 */
public class ChatClientListener implements MessageListener<Client>{
    GameClient gameClient;
    /**
     * 
     * @param gameClient
     */
    public  ChatClientListener(GameClient gameClient){
        this.gameClient = gameClient;
    }
   /**
    * 
    * @param source
    * @param m
    */
   public void messageReceived(Client source, Message m) {
        if(m instanceof ChatClientMessage){
            ChatClientMessage chatClientMessage = (ChatClientMessage) m;
            if(chatClientMessage.isNewUser()){
                gameClient.addChatter(new Chatter(chatClientMessage.getName(),chatClientMessage.getUUID()));
                gameClient.addChatText(chatClientMessage.getName(), chatClientMessage.getMessage());
            }
              gameClient.addChatText(chatClientMessage.getName(), chatClientMessage.getMessage());
            
        }
        
    }
    
}
